package com.example.springbootcaffeinedemo.common2;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.stats.CacheStats;
import com.github.benmanes.caffeine.cache.stats.StatsCounter;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/04/18  14:43
 * @Description: 测试CacheStats缓存的各项指标-使用自定义的缓存状态收集器
 */
public class MyCacheStatsCounter implements StatsCounter {

    @Override
    public void recordHits(@NonNegative int i) {
        System.out.println("命中次数：" + i);
    }

    @Override
    public void recordMisses(@NonNegative int i) {
        System.out.println("未命中次数：" + i);
    }

    @Override
    public void recordLoadSuccess(@NonNegative long l) {
        System.out.println("加载成功次数：" + l);
    }

    @Override
    public void recordLoadFailure(@NonNegative long l) {
        System.out.println("加载失败次数：" + l);
    }

    @Override
    public void recordEviction() {
        System.out.println("因为缓存大小限制，执行了一次缓存清除工作");
    }

    @Override
    public void recordEviction(@NonNegative int weight) {
        //StatsCounter.super.recordEviction(weight);
        System.out.println("因为缓存权重限制，执行了一次缓存清除工作，清除的数据的权重为：" + weight);

    }

    @Override
    public void recordEviction(@NonNegative int weight, RemovalCause cause) {
        StatsCounter.super.recordEviction(weight, cause);
    }

    @Override
    public @NonNull CacheStats snapshot() {
        return null;
    }
}
